Skip to content

Throw a clear error when an Execute command contains whitespace#3122

Merged
mgravell merged 3 commits into
StackExchange:mainfrom
arpitjain099:chore/execute-whitespace-guard
Jul 10, 2026
Merged

Throw a clear error when an Execute command contains whitespace#3122
mgravell merged 3 commits into
StackExchange:mainfrom
arpitjain099:chore/execute-whitespace-guard

Conversation

@arpitjain099

Copy link
Copy Markdown
Contributor

Fixes #2689, which you reopened as a usability bug. Calling something like db.Execute("ACL SETUSER x") passes the whole line as a single command token, so it goes out as one unknown command and the only feedback is an opaque ERR unknown command from the server. Since a redis command token never has internal whitespace, that call is always a mistake, so the ExecuteMessage constructor now checks for it up front (right alongside the existing too-many-args and command-disabled guards) and throws a RedisCommandException that names the command and points at the correct token-per-argument form.

I couldn't run the integration suite locally without a server, but the guard fires purely client-side in the constructor, so I added unit tests to AdhocMessageRoundTrip that build the message directly (matching the existing disabled-command tests): a few whitespace inputs throw, and Execute("ACL", "SETUSER", "x") still constructs fine.

Happy to switch to auto-splitting instead if you'd prefer that direction, but your reopen comment read as leaning toward the throw, so I went with that.

Execute("ACL SETUSER x") passes a whole command line as the single command
token, which gets sent as one unknown command and comes back as an opaque
server error. Since a redis command token never contains internal whitespace,
this is always a caller mistake, so the ExecuteMessage constructor now fails
fast with an ArgumentException-style RedisCommandException that names the
offending command and shows the correct token-per-argument form. Resolves StackExchange#2689.

Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
mgravell added 2 commits July 10, 2026 11:39
limit to simple space; if people are being *that* creative, that's on them
Removed test case for command with tab character.
@mgravell

Copy link
Copy Markdown
Collaborator

Intent is great, but IMO we should restrict ourselves to the "obvious" case, ' ' - looping char-by-char testing for every possible white-space condition is more expensive than we really want, with a non-trivial impact for libs like NRedisStack; I've tweaked to limit it to simple space.

@mgravell mgravell merged commit 0b03ed1 into StackExchange:main Jul 10, 2026
7 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Execute should check for whitespace (was: ACL Management)

2 participants